import Vue from 'vue'
import Router from 'vue-router'
import labHome from '@/views/labHome.vue'
import researchTeam from '@/views/researchTeam.vue'
import newestProduction from '@/views/newestProduction.vue'
import labInstruction from '@/views/labInstruction.vue'
import labStructure from '@/views/labStructure.vue'
import researchDirection from '@/views/researchDirection.vue'
import researchAchievement from '@/views/researchAchievement.vue'
import teacherZhang from '@/views/teacher/teacherZhang.vue'
import Dongke from '@/views/member/213Dongke.vue'
import Zhaoxinlei from '@/views/member/213Zhaoxinlei.vue'
import Donglijia from '@/views/member/213Donglijia.vue'
import Lizhichao from '@/views/member/213Lizhichao.vue'
import bigModel from '@/views/labFeature/bigModel.vue'
import actionRecognition from '@/views/labFeature/actionRecognition.vue'
import edgeComputer from '@/views/labFeature/edgeComputer.vue'
import computerVisions  from '@/views/labFeature/computerVisions.vue'
import deepStudy from '@/views/labFeature/deepStudy.vue'

Vue.use(Router)

const router=new Router({
  base:process.env.VUE_APP_BASE_PATH,
  mode:'hash',
  routes: [
    {
      path: '/',
      name: 'labHome',
      component: labHome
    },
    {
      path:'/labInstruction',
      name:'labInstruction',
      component:labInstruction
    },
    {
      path:'/labStructure',
      name:'labStructure',
      component:labStructure
    },
    {
      path: '/researchTeam',
      name: 'researchTeam',
      component: researchTeam
    },
    {
      path: '/newestProduction',
      name: 'newestProduction',
      component: newestProduction
    },
    {
      path: '/researchDirection',
      name: 'researchDirection',
      component: researchDirection
    },
    {
      path: '/researchAchievement',
      name: 'researchAchievement',
      component: researchAchievement
    },
    {
      path: '/researchTeam/teacherZhang',
      name: 'teacherZhang',
      component: teacherZhang
    },
    {
      path: '/researchTeam/213Dongke',
      name: '213Dongke',
      component: Dongke
    },
    {
      path: '/researchTeam/213Zhaoxinlei',
      name: '213Zhaoxinlei',
      component: Zhaoxinlei
    },
    {
      path: '/researchTeam/213Donglijia',
      name: '213Donglijia',
      component: Donglijia
    },
    {
      path: '/researchTeam/213Lizhichao',
      name: '213Lizhichao',
      component: Lizhichao
    },
    {
      path: '/labInstruction/bigModel',
      name: 'bigModel',
      component: bigModel
    },
    {
      path: '/labInstruction/actionRecognition',
      name: 'actionRecognition',
      component: actionRecognition
    },
    {
      path: '/labInstruction/edgeComputer',
      name: 'edgeComputer',
      component: edgeComputer
    },
    {
      path: '/labInstruction/computerVisions',
      name: 'computerVisions',
      component: computerVisions
    },
    {
      path: '/labInstruction/deepStudy',
      name: 'deepStudy',
      component: deepStudy
    },
    {
      path: "/algorithmInfo/:id", // 使用动态路由参数
      name: "AlgorithmInfo",
      component: () => import('@/views/algorithm/AlgorithmInfo.vue'),
      props: true,
    },
    {
      path: '/mall',
      name: 'Mall',
      component: () => import('@/views/algorithm/Mall.vue')
    },
    {
      path: "/algorithmApplyDetail/:id",
      name: "AlgorithmApplyDetail",
      component: () => import('@/views/algorithm/AlgorithmApplyDetail.vue'),
      props: true,
    },
    {
      path: '/algorithmApply',
      name: 'AlgorithmApply',
      component: () => import('@/views/algorithm/AlgorithmApply.vue')
    },


  ],
   scrollBehavior(to, from, savedPosition) {
    // 如果有保存的位置（浏览器前进/后退），则使用保存的位置
    if (savedPosition) {
      return savedPosition;
    }
    // 否则滚动到页面顶部
    return { x: 0, y: 0 };
  },
})

// 全局捕获重复导航错误
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => {
    // 如果是重复导航错误，就忽略它，不向外抛出
    if (err.name !== 'NavigationDuplicated') {
      return Promise.reject(err)
    }
  })
}

export default router
